Smile provides tools for dynamical editing of scripts - in other terms, for creating / editing a script ... by script. First of them, the coercions between script and text.
----------------------------
set script of window 1 to "-- aargh !"
----------------------------
You may also want to use the "script of" command, applied to a file reference.
----------------------------
script of theFile as text --> returns the script contained in theFile
----------------------------
Note the use of "script of". Use "script of theFile" (instead of "load script" and "store script") to read scripts as text, and use "LoadResource / PutResource" if you want to manipulate scripts. See Satimage osax for these commands.
Handling scripts as objects
Scripts behave most like objects, with the (virtual) following dictionary :
Class script :
Elements:
variable by numeric index, name
handler by numeric index, name
Properties:
container reference [r/o] -- the object containing the script
parent script [r/o] -- the parent script
The container property exists for the scripts attached to some Smile object.
Here are some examples.
----------------------------
name of handlers of class script of window 1
----------------------------
name of every variable of globals
----------------------------
handler "MaxInList" of class script of window 1 as text
----------------------------
Creating object classes
Smile lets you create dynamically (i.e., with a script) classes, attach class scripts to them, and thus build hierarchical systems.
For example, suppose you want a special class for Internet-aware text windows. "Internet" should contain Internet-oriented handlers. Save it in the "Class Scripts" folder. Add the following line in the InitAppli() handler of the "Application" script to give it a signature. (the four-characters code is up to you).
----------------------------
make new class script with properties {class script:"INet", parent:text window, path name:"Internet"}
----------------------------
Then use the following block to create each Internet-aware text window.
----------------------------
set theWind to make new text window with properties {class script:"INet"}
----------------------------
Once saved, the window will keep memory of its class script.
To build a hierarchy, you will use the "parent" property. Suppose you want to derive a class of text windows from "INet" windows :
----------------------------
make new class script with properties {class script:"html", parent:"INet", path name:"WebLib"}